/**
 * 项目名：pactera-boot
 * 包名：com.pactera.controller.sys.api
 * 文件名：SysUserApi.java
 * 版本信息：1.0.0
 * 日期：2018年11月27日-上午11:03:31
 * Copyright (c) 2018 Pactera 版权所有
 */
package com.pactera.controller.common.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.pactera.common.constants.Constants;
import com.pactera.common.utils.JsonResponseUtils;
import com.pactera.model.SysUser;
import com.pactera.service.common.DynamicDataSourceService;
import com.pactera.vo.common.BaseRespVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "DynamicDataSourceApi-动态数据源接口")
@RestController
@RequestMapping("/api/datasource")
public class DynamicDataSourceApi{
	
	@Autowired
	private DynamicDataSourceService dynamicDataSourceService;
	
	
	@ApiOperation(value = "mybatis-def-用户列表", notes = "mybatis-def-用户列表")
	@RequestMapping(value="/getMyUserListByDef", method = RequestMethod.POST)
	public BaseRespVo getSysUserListByMapperDef() throws Exception {
		return JsonResponseUtils.successData(BaseRespVo.class, dynamicDataSourceService.getSysUserListByDef());
	}
	
	@ApiOperation(value = "mybatis-ds1-用户列表", notes = "mybatis-ds1-用户列表")
	@RequestMapping(value="/getMyUserListByDs1", method = RequestMethod.POST)
	public BaseRespVo getSysUserListByMapperDs1() throws Exception {
		
		return JsonResponseUtils.successData(BaseRespVo.class, dynamicDataSourceService.getSysUserListByDs1());
	}
	
	
	@ApiOperation(value = "mybatis-def-添加用户", notes = "新增用户-master用户数据")
	@RequestMapping(value="/addUserByDef", method = RequestMethod.POST)
	public BaseRespVo addUserByDef(SysUser sysUser) throws Exception {
		boolean isSuccess = dynamicDataSourceService.saveSysUserByDef(sysUser);	
		if(isSuccess){
			return JsonResponseUtils.success(BaseRespVo.class);
		}else{
			return JsonResponseUtils.failure(BaseRespVo.class);
		}
	}
	
	
	@ApiOperation(value = "mybatis-def-用户分页列表", notes = "mybatis-def-用户分页列表")
	@RequestMapping(value="/getSysUserPageByDef", method = RequestMethod.POST)
	public BaseRespVo getSysUserPageByDef(
			@RequestParam(value="pageNo",defaultValue=Constants.PAGE_NUM) int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize) throws Exception {
		
		return JsonResponseUtils.successData(BaseRespVo.class, dynamicDataSourceService.getSysUserPageByDef(pageNo, pageSize));
	}
	
	@ApiOperation(value = "mybatis-ds2-用户分页列表", notes = "mybatis-ds2-用户分页列表")
	@RequestMapping(value="/getSysUserPageByDs2", method = RequestMethod.POST)
	public BaseRespVo getSysUserPageByDs2(
			@RequestParam(value="pageNo",defaultValue=Constants.PAGE_NUM) int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize) throws Exception {
		
		return JsonResponseUtils.successData(BaseRespVo.class, dynamicDataSourceService.getSysUserPageByDs2(pageNo, pageSize));
	}
}
